<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>型号关系</title>
    <script src="../../static/bootstrap5.0.1/bootstrap5/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="../../static/bootstrap5.0.1/bootstrap5/bootstrap.min.css">
    <link rel="stylesheet" href="../../static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/layuiadmin/style/admin.css" media="all">
    <script src="../../static/layuiadmin/layui/layui.js"></script>
    <link rel="stylesheet" href="../../static/css/common.css">
    <style>
        .bx {
            margin-left: 50px;
            margin-top: 50px;
        }

        .layui-table-cell {
            height: 40px;
            line-height: 40px;
        }

        .layui-input-block {
            margin-left: 150px;
            min-height: 36px;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <div class="layui-inline tp">
        <div class="layui-form-item" style="margin-left: -110px;">
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入型号"
                       autocomplete="off" class="layui-input" id="product_model_search">
            </div>
        </div>
    </div>
    <!--    <div class="layui-inline">-->
    <!--        <label class="layui-form-label" style="width: auto;">日志创建时间</label>-->
    <!--        <div class="layui-input-inline">-->
    <!--            <input type="text" name="date" id="log_date_search" lay-verify="date" placeholder="yyyy-MM"-->
    <!--                   autocomplete="off"-->
    <!--                   class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->
    <div class="layui-inline tp1">
        <div class="layui-form-item">
            <button id="searchconfig" class="btn btn-primary">搜索</button>
<!--            <button id="datainit" class="btn btn-danger">新增</button>-->
        </div>
    </div>
    <div id="show_table" lay-filter="show_table">
    </div>
</div>
<div id="addwl" style="display: none;">
    <div class="layui-form tp">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: auto;" for="product_model">型 号</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" id="product_model" name="zc_name" lay-verify="required" placeholder="请输入型号"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label" style="width: auto;" for="product_model">产品名称</label>-->
<!--            <div class="layui-input-block" style="width: 250px;">-->
<!--                <input type="text" id="product_name" name="zc_name" lay-verify="required" placeholder="请输入型号"-->
<!--                       autocomplete="off"-->
<!--                       class="layui-input">-->
<!--            </div>-->
<!--        </div>-->
    </div>
</div>
<div style="display: none;" id="show_bind_msg">
    <div id="bind_table" lay-filter="bind_table"></div>
</div>
</body>
<script type="text/html" id="operator">
    <!--    <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</button>-->
    <!--    <button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="execute">查看绑定条件</button>-->
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
</script>
<script>
    layui.use(["table", "jquery", "layer", "laydate"], function () {
            var table = layui.table;
            var $ = layui.jquery;
            var layer = layui.layer;
            let laydate = layui.laydate;
            laydate.render({
                elem: "#log_date_search",
                value: new Date(),
                format: "yyyy-MM",
                type: 'month'
            })
            tableRender(null);

            function tableRender(param) {
                table.render({
                    elem: "#show_table",
                    method: "post",
                    url: "/api/xh/get_xh_list",
                    where: param,
                    page: true,
                    limit: 8,
                    limits: [8, 10, 20, 30],
                    cols: [[
                        {
                            field: "id",
                            title: "型号编号",
                            width: 200,
                            align: "center",
                            style: 'background-color:white;color:gray;opacity:0.9;'
                        },
                        {
                            field: "product_model",
                            title: "型 号",
                            width: 200,
                            align: "center",
                            style: 'background-color:white;color:gray;opacity:0.9;'
                        },
                        // {
                        //     field: "product_name",
                        //     title: "备注信息",
                        //     align: "center",
                        //     width: 200,
                        //     style: 'background-color:white;color:gray;opacity:0.9;'
                        // },
                        // {
                        //     field: "log_msg",
                        //     title: "日志信息",
                        //     align: "center",
                        //     width: 400,
                        //     style: 'background-color:white;color:red;opacity:0.9;'
                        // },
                        // {
                        //     field: "log_args",
                        //     title: "日志参数",
                        //     align: "center",
                        //     width: 200,
                        //     style: 'background-color:white;color:purple;opacity:0.9;'
                        // }
                        // ,
                        {
                            title: "操 作",
                            toolbar: "#operator",
                            align: "center",
                            style: 'background-color:white;color:gray;opacity:0.9;'
                        }
                    ]]
                })
            }

            table.on('tool(show_table)', function (obj) {
                let row_data = obj.data;
                if (obj.event === 'del') {
                    let param = {
                        id: row_data["id"]
                    }
                    $.post("/api/xh/del", param, function (res) {
                        if (res.code === 200) {
                            layer.msg(res.msg, {icon: 6, time: 1500}, function () {
                                tableRender(null)
                                layer.close(idx);
                            })
                        } else {
                            layer.msg(res.msg, {icon: 6, time: 1500}, function () {
                                // tableRender(null)
                            })
                        }
                    })
                }
                if (obj.event === 'execute') {

                    //新增
                    let open_index = layer.open({
                        type: 1,
                        content: $('#show_bind_msg'),
                        title: '组织绑定信息',
                        area: ['1000px', '400px'],
                        btn: ['确定', '取消'],
                        yes: function (index, layerout) {

                        },
                        btn2: function (index, layer) {

                        },
                        closeBtn: function (index, layer) {

                        },
                        success: function () {
                            table.render({
                                elem: "#bind_table",
                                method: "post",
                                url: "/order/get_bind_msg",
                                where: row_data,
                                page: true,
                                limit: 8,
                                limits: [8, 10, 20, 30],
                                cols: [[
                                    {
                                        field: "org_name",
                                        title: "组织名称",
                                        align: "center",
                                        width: 150,
                                        style: 'background-color:white;color:gray;opacity:0.9;'
                                    },
                                    {
                                        field: "lx",
                                        title: "条件类型",
                                        align: "center",
                                        width: 120,
                                        style: 'background-color:white;color:gray;opacity:0.9;'
                                    },
                                    {
                                        field: "filter_type",
                                        title: "条件符号",
                                        align: "center",
                                        width: 100,
                                        style: 'background-color:white;color:gray;opacity:0.9;'
                                    },
                                    {
                                        field: "filter_value",
                                        title: "条件值",
                                        align: "center",
                                        style: 'background-color:white;color:gray;opacity:0.9;'
                                    },
                                    {
                                        field: "bind_id",
                                        title: "所属分组编号",
                                        align: "center",
                                        style: 'background-color:white;color:gray;opacity:0.9;'
                                    },
                                ]]
                            })
                            // $.post("/order/get_bind_msg", row_data, function (res) {
                            //     if (res.code === 200) {
                            //
                            //     } else {
                            //         layer.msg(res.msg, {icon: 2, time: 1500}, function () {
                            //             tableRender(null)
                            //         })
                            //     }
                            // })
                        }
                    })
                }
            })

            $("#searchconfig").click(function () {
                search_func();
            })

            function search_func() {
                let material_name = $("#material_name").val()
                tableRender({
                    "material_name": material_name
                });
            }

            $('#order_no_search').bind('keypress', function (event) {
                if (event.keyCode === 13) {
                    search_func();
                }
            })

            $("#datainit").click(function () {
                /**
                 // 显示加载层
                 // let loadIndex = layer.load(0, {
                 //     shade: [0.5, '#fff'],
                 //     zIndex: layer.zIndex,
                 //     content: "正在订单校验中...请稍后"
                 // });
                 // 在顶层显示加载层
                 // layer.setTop();
                 // $.post("/order/cal/order_cl", {}, function (res) {
                 //     // layer.close(loadIndex);
                 //     if (res.code === 200) {
                 //         layer.msg(res.msg, {icon: 6, time: 3000}, function () {
                 //             tableRender(null)
                 //         })
                 //     } else {
                 //         layer.msg(res.msg, {icon: 2, time: 3000}, function () {
                 //             // tableRender(null)
                 //         })
                 //     }
                 //
                 // })**/

                let idx = layer.open(
                    {
                        type: 1,
                        content: $('#addwl'),
                        title: '新增资产类型',
                        area: ['500px', '200px'],
                        btn: ['确定', '取消'],
                        yes: function (index, layerout) {
                            let zc_name = $("#product_model").val()
                            if (zc_name === undefined || zc_name === "") {
                                layer.msg("型号不能为空", {icon: 2, time: 1500}, function () {
                                    //tableRender(null)
                                })
                                return;
                            }
                            let param = {
                                product_model: zc_name
                            }
                            $.post("/api/xh/add_xh", param, function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 6, time: 1500}, function () {
                                        tableRender(null)
                                        layer.close(idx);
                                    })
                                } else {
                                    layer.msg(res.msg, {icon: 6, time: 1500}, function () {
                                        // tableRender(null)
                                    })
                                }
                            })
                        },
                        btn2: function (index, layer) {

                        },
                        success: function () {

                        }
                    }
                );
            })
        }
    )


</script>
</html>